import ReactECharts from "echarts-for-react";
import {history} from "@@/core/history";
import {useEffect, useState} from "react";
import {Detail02Contest, Detail02Teacher} from "@/services/Province/Dashboard";
import {ProvinceAllUrl} from "@/utils/format";
import {Link} from "@umijs/preset-dumi/lib/theme";

const Gmm02_5 = (props) => {
  // echarts Demo 数据
  // const options = {
  //   title: {
  //     text: '学生国内外竞赛获奖情况',
  //     // subtext: 'Fake Data',
  //     left: 'center'
  //   },
  //   tooltip: {
  //     trigger: 'item'
  //   },
  //   // legend: {
  //   //   orient: 'vertical',
  //   //   left: 'left'
  //   // },
  //   series: [
  //     {
  //       name: '',
  //       type: 'pie',
  //       radius: '70%',
  //       data: [
  //         { value: 12, name: '特等奖' },
  //         { value: 4, name: '一等奖'},
  //         { value: 1, name: '二等奖' },
  //         { value: 3, name: '团体奖'},
  //       ],
  //       emphasis: {
  //         itemStyle: {
  //           shadowBlur: 10,
  //           shadowOffsetX: 0,
  //           shadowColor: 'rgb(0,0,0)'
  //         }
  //       }
  //     }
  //   ]
  // };

  const urlArr = history.location.pathname.split('/')
  const school = urlArr[urlArr.length - 1]
  const subject = urlArr[urlArr.length - 2]
  const schoolSubject = school + '-' + subject
  const [options, setoptions] = useState({})
  const [reload, setreload] = useState(false)
  useEffect(() => {
    Detail02Contest({subject: schoolSubject}).then(res => {
      if (res.status === 0) {
        setoptions({
          title: {
            text: '学生国内外竞赛获奖情况',
            // subtext: 'Fake Data',
            left: 'center'
          },
          tooltip: {
            trigger: 'item'
          },
          // legend: {
          //   orient: 'vertical',
          //   left: 'left'
          // },
          series: [
            {
              name: '',
              type: 'pie',
              radius: '70%',
              data: res.data,
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgb(0,0,0)'
                }
              }
            }
          ]
        })
      }
    })
  }, [reload])

  const url = ProvinceAllUrl(school, subject, '2_2_6', '学生国内外竞赛获奖')

  return <>
    <Link to={url}>详情</Link>
    <ReactECharts style={{width: 500, height: 400}} option={options} />
  </>
}

export default Gmm02_5
